package com.gitee.xhs.customFunction;

import com.gitee.xhs.sampleRecod.transactionRecord.Transaction;
import org.apache.flink.api.common.functions.ReduceFunction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author BigHead
 * @date 2022/7/19 13:42
 * @description OperatorReduce
 */
public class OperatorReduce implements ReduceFunction<Transaction> {

    private static final Logger logger = LoggerFactory.getLogger(OperatorReduce.class);
    private static final Double MAX_AMOUNT_INTERVAL = 6d;

    @Override
    public Transaction reduce(Transaction value1, Transaction value2) throws Exception {
        double sumValue = value1.getAmount() + value2.getAmount();

        if (sumValue <= value2.getAccountId() * MAX_AMOUNT_INTERVAL) {
            value2.setAmount(sumValue);
        }

        return value2;
    }
}
